<template>  
    <view class="container">  
		<view class="user-section">
			<view class="bg"></view>
			<view class="user-info-box">
				<view class="portrait-box">
					<image class="portrait" :src="'/static/logo.jpg'"></image>
				</view>
				<view class="info-box">
					<text class="username">{{ userInfo.nickname || userInfo.username }}</text>
				</view>
			</view>
			<!-- <view class="vip-card-box">
				<view class="tit tag">
					<text class="myicon icon-huiyuan1"></text>
					DCloud会员
				</view>
				<view class="b-btn">
					立即开通
				</view>
			</view> -->
		</view>
		
		<view 
			class="cover-container"
			:style="[{
				transform: coverTransform,
				transition: coverTransition
			}]"
			@touchstart="coverTouchstart"
			@touchmove="coverTouchmove"
			@touchend="coverTouchend"
		>
			<view class="tj-sction">
				<view class="tj-item">
					<text class="num">{{ userInfo.money }}</text>
					<text>余额</text>
				</view>
				<!-- <view class="tj-item">
					<text class="num">0</text>
					<text>优惠券</text>
				</view>
				<view class="tj-item">
					<text class="num">20</text>
					<text>积分</text>
				</view> -->
			</view>
			<!-- 订单 -->
			<view class="order-section">
				<view class="order-item" @click="nav('/pages/shop/order/orderlist?status=')" hover-class="common-hover"  :hover-stay-time="50">
					<text class="myicon icon-dingdan"></text>
					<text>全部订单</text>
				</view>
				<view class="order-item" @click="nav('/pages/shop/order/orderlist?status=1')"  hover-class="common-hover" :hover-stay-time="50">
					<text class="myicon icon-daifukuan"></text>
					<text>待付款</text>
				</view>
				<view class="order-item" @click="nav('/pages/shop/order/orderlist?status=2')" hover-class="common-hover"  :hover-stay-time="50">
					<text class="myicon icon-daishouhuo"></text>
					<text>待收货</text>
				</view>
				<view class="order-item" @click="nav('/pages/shop/order/orderlist?status=3')" hover-class="common-hover"  :hover-stay-time="50">
					<text class="myicon icon-tuikuan"></text>
					<text>退款/售后</text>
				</view>
			</view>
			<!-- 浏览历史 -->
			<view class="history-section icon">
				<view class="sec-header">
					<text class="myicon icon-lishijilu"></text>
					<text>浏览历史</text>
				</view>
				<scroll-view scroll-x class="h-list" v-for="(item, index) in operalogList.data">
					<image @click="nav('/pages/product/product')" :src="baseURL+'/'+item.opera_info.logo_img" mode="aspectFill"></image>
				</scroll-view>
			</view>
			<view class="nav-section">
				<view class="item justify-between align-center" @click="nav('/pages/product/product')">
					<view class="justify-between align-center">
						<view class="myicon icon-shouhuodizhi"></view>
						<view style="margin-left: 5px;">我的追剧</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
				<view class="item justify-between align-center" @click="nav('/pages/product/product')">
					<view class="justify-between align-center">
						<view class="myicon icon-shouhuodizhi"></view>
						<view style="margin-left: 5px;">我的观看</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
				<view class="item justify-between align-center" @click="nav('/pages/product/product')">
					<view class="justify-between align-center">
						<view class="myicon icon-shouhuodizhi"></view>
						<view style="margin-left: 5px;">我的充值</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
				<view class="item justify-between align-center" @click="nav('/pages/product/product')">
					<view class="justify-between align-center">
						<view class="myicon icon-shouhuodizhi"></view>
						<view style="margin-left: 5px;">我的消费</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
				<view class="item justify-between align-center" @click="call_tel('13245000009')">
					<view class="justify-between align-center">
						<view class="myicon icon-kefu"></view>
						<view style="margin-left: 5px;">联系客服</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
				<view class="item justify-between align-center" v-if="userInfo.is_leader==1">
					<view class="justify-between align-center">
						<view class="myicon icon-dianhua"></view>
						<view style="margin-left: 5px;">我的团队</view>
					</view>
					<view class="myicon icon-xiangyou1"></view>
				</view>
			</view>
			
			
		</view>
			
		<view :style="{height:`${constant.bottom_bar_height}px`}">
			<BottomBar v-model='barIndex' :barlists="barlists"/>
		</view>
    </view>  
</template>  
<script>
	import config from '@/pages/shop/config.js'
	let startY = 0, moveY = 0, pageAtTop = true;
    export default {
		data(){
			return {
				baseURL:this.baseURL,
				barIndex:4,
				constant:this.constant,
				barlists:config.barlists,
				coverTransform: 'translateY(0px)',
				coverTransition: '0s',
				moving: false,
				userInfo: null,
				operalogList: null
			}
		},
		onLoad(){
			this.get('user/user_info').then(({code,user_info})=>{
				if(code==1){
					this.userInfo = user_info;
					if(user_info){
						this.get('crud/list',{table:'operalog', limit: 10, join_table: 'opera'}).then(({code,paginate})=>{
							if(code==1){
								this.operalogList=paginate;
							}
						});
					} else {
						
					}
					
				}
			})
		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.nav('/pages/set/set');
			}else if(index === 1){
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
        methods: {
			/**
			 *  会员卡下拉和回弹
			 *  1.关闭bounce避免ios端下拉冲突
			 *  2.由于touchmove事件的缺陷（以前做小程序就遇到，比如20跳到40，h5反而好很多），下拉的时候会有掉帧的感觉
			 *    transition设置0.1秒延迟，让css来过渡这段空窗期
			 *  3.回弹效果可修改曲线值来调整效果，推荐一个好用的bezier生成工具 http://cubic-bezier.com/
			 */
			coverTouchstart(e){
				if(pageAtTop === false){
					return;
				}
				this.coverTransition = 'transform .1s linear';
				startY = e.touches[0].clientY;
			},
			coverTouchmove(e){
				moveY = e.touches[0].clientY;
				let moveDistance = moveY - startY;
				if(moveDistance < 0){
					this.moving = false;
					return;
				}
				this.moving = true;
				if(moveDistance >= 80 && moveDistance < 100){
					moveDistance = 80;
				}
		
				if(moveDistance > 0 && moveDistance <= 80){
					this.coverTransform = `translateY(${moveDistance}px)`;
				}
			},
			coverTouchend(){
				if(this.moving === false){
					return;
				}
				this.moving = false;
				this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
				this.coverTransform = 'translateY(0px)';
			}
        }  
    }  
</script>  
<style lang='scss'>
	%flex-center {
	 display:flex;
	 flex-direction: column;
	 justify-content: center;
	 align-items: center;
	}
	%section {
	  display:flex;
	  justify-content: space-around;
	  align-content: center;
	  background: #fff;
	  border-radius: 10upx;
	}

	.user-section{
		height: 520upx;
		padding: 80upx 30upx 0;
		position:relative;
		.bg{
			position:absolute;
			left: 0;
			top: 0;
			width: 100%;
			height: 100%;
			filter: blur(1px);
			opacity: .7;
			background: linear-gradient(to bottom, $base-color, #ffffff);;
		}
	}
	.user-info-box{
		height: 180upx;
		display:flex;
		align-items:center;
		position:relative;
		z-index: 1;
		.portrait{
			width: 130upx;
			height: 130upx;
			border:5upx solid #fff;
			border-radius: 50%;
		}
		.username{
			font-size: $font-lg + 6upx;
			color: $font-color-dark;
			margin-left: 20upx;
		}
	}

	.vip-card-box{
		.tag{
		  position: relative;
		  border-radius: 4px 4px 4px 0px;
		  color: #fff;
		  padding: 2px 6px;
		  font-size: 10px;
		  line-height: 16px;
		  background: linear-gradient(to right bottom, rgba(255, 255, 255, 0.4), transparent) var(--bg, $base-color);
		  background-blend-mode: soft-light;
		}
		.tag::before{
		  content: '';
		  position: absolute;
		  width: 3px;
		  height: 3px;
		  left: 0;
		  bottom: -3px;
		  background-color: inherit;
		  filter: brightness(.7);
		  clip-path: polygon(0 0, 100% 0, 100% 100%);
		}
		
		.b-btn{
			position: relative;
		}
		.b-btn:after{
			content: ' ';
			border-top: 8px solid transparent;
			border-bottom: 8px solid transparent;
			border-left: 12px solid #F0981C;
			position: absolute;
			bottom: 15px;
			right: -12px;
			font-size: 10px;
		}
	
		
		
		display:flex;
		justify-content: space-between;
		color: #f7d680;
		background: linear-gradient(left, rgba(0,0,0,.7), rgba(0,0,0,.8));
		border-radius: 16upx 16upx 0 0;
		overflow: hidden;
		position: relative;
		padding: 20upx 24upx;
		.tit{
			font-size: $font-base+2upx;
			color: #f7d680;
			margin-bottom: 28upx;
			.myicon{
				color: #f6e5a3;
				margin-right: 16upx;
			}
		}
	}
	.cover-container{
		background: $page-color-base;
		margin-top: -150upx;
		padding: 0 30upx;
		position:relative;
		background: #f5f5f5;
		padding-bottom: 20upx;
	}
	.tj-sction{
		@extend %section;
		.tj-item{
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #75787d;
		}
		.num{
			font-size: $font-lg;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}
	.order-section{
		@extend %section;
		padding: 28upx 0;
		margin-top: 20upx;
		.order-item{
			@extend %flex-center;
			width: 120upx;
			height: 120upx;
			border-radius: 10upx;
			font-size: $font-sm;
			color: $font-color-dark;
		}
		.myicon{
			font-size: 48upx;
			margin-bottom: 18upx;
			color: #fa436a;
		}
		.icon-shouhoutuikuan{
			font-size:44upx;
		}
	}
	.history-section{
		padding: 30upx 0 0;
		margin-top: 20upx;
		background: #fff;
		border-radius:10upx;
		.sec-header{
			display:flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;
			.myicon{
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}
		.h-list{
			white-space: nowrap;
			padding: 30upx 30upx 0;
			image{
				display:inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}
	}
	.nav-section{
		padding: 30upx 0 0;
		margin-top: 20upx;
		border-radius:10upx;
		.item{
			background: #fff;
			margin-bottom: 4px;
			border-radius: 10upx;
			padding: 10px 30upx;
			.icon-xiangyou1{
				color: $font-color-disabled;
			}
		}
	}
</style>